package com.qingguatang.java5minute.control;

import com.qingguatang.java5minute.model.Comment;
import com.qingguatang.java5minute.model.SongInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SongInfoControl {
    private static Map<String, SongInfo> songInfoMap = new HashMap<>();

    @Autowired
    private CommentPostControl commentPostControl;
    @RequestMapping(value = "/songInfo")
    public String index(String songId, ModelMap modelMap) {
        if (songId == null) {
            songId = "35847388";
        }
        SongInfo songInfo = songInfoMap.get(songId);
        modelMap.addAttribute("song", songInfo);
        List<Comment> comments=commentPostControl.getComments(songId);
        modelMap.addAttribute("comments",comments);
        return "index";
    }

    @RequestMapping("/songInfo/get")
    @ResponseBody
    public SongInfo get(String songId) {
        SongInfo songInfo = songInfoMap.get(songId);
        return songInfo;
    }

    @PostConstruct
    public void init() {
        SongInfo songInfo = new SongInfo();
        songInfo.setId("35847388");
        songInfo.setName("Hello");
        songInfo.setSinger("Adele");
        songInfo.setAlbumName("Hello");
        songInfo.setCommentcount(92731);
        songInfo.setLyrics("Hello, it's me<br>" +
                "你好吗 是我<br>" +
                "I was wondering if after all these years you'd like to meet<br>" +
                "我犹豫着要不要给你来电 不确定多年后你是否还愿相见<br>" +
                "To go over everything<br>" +
                "愿意闲聊寒暄 细数从前<br>" +
                "They say that time's supposed to heal ya but I ain't done much healing<br>" +
                "人们都说时间能治愈一切 但我却似乎没有更好一点<br>" +
                "Hello, can you hear me<br>" +
                "嘿 你在听吗<br>" +
                "I'm in California dreaming about who we used to be<br>" +
                "我还总能想起我们过去的种种美好");
        songInfo.setAlbumImg("http://p1.music.126.net/PrO7oPvnjvH4xdujdGbf2w==/1407374890649284.jpg?param=130y130");
        songInfoMap.put("35847388", songInfo);


        songInfo = new SongInfo();
        songInfo.setId("19081556");
        songInfo.setName("No Promises");
        songInfo.setSinger("Shayne Ward");
        songInfo.setAlbumName("Shayne Ward");
        songInfo.setCommentcount(1913);
        songInfo.setLyrics("Hey baby, when we are together, doing things that we love.<br>" +
                "还记得吗，宝贝，当我们在一起的时候，我们一起做我们喜欢的事情<br>" +
                "Every time you're near I feel like I’m in heaven, feeling high<br>" +
                "每次你靠近我的时候，我犹如身在天堂，是那样的快乐<br>" +
                "I don’t want to let go, girl.<br>" +
                "女孩，我并不想放你走<br>" +
                "I just need you to know girl.<br>" +
                "这就是我需要让你知道的");
        songInfo.setAlbumImg("http://p2.music.126.net/pXAo_jUn2M237jcHOAmS_A==/18221106696070571.jpg?param=130y130");
        songInfoMap.put("19081556",songInfo);
    }
}
